/*
 * swap.h
 *
 *  Created on: 2012-6-27
 *  Author: zyh
 */
#ifndef SWAP_H
#define SWAP_H

#include <devices/block.h>
#include <list.h>
#include <bitmap.h>
#include "vm/frame.h"
#include "vm/page.h"

/*[zyh]swap表的项*/
struct swap_entry{
	struct list_elem elem;
	uintptr_t page_number;
	block_sector_t start;	//一个slot的起始扇区
	struct thread* owner;	//所属的线程
    bool writable;			//是否可写
};

struct lock swap_lock;		//swap表的全局锁

//初始化swap table
void swap_init(void);

/*
 * 用于页面置换,page_number为请求的页的页号,
 * 如果是栈增长，则stack为true，否则为false
 */
bool swap_replace(uintptr_t page_number,bool stack);

//当进程退出时，调用该函数，清除它在swap中的空间
void swap_free_slot(struct thread* t);

#endif

